package com.ruoyi.project.api;


import com.ruoyi.project.wx.reserve.domain.WxMakeCar;
import com.ruoyi.project.wx.reserve.service.WxMakeCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx/reserver")
public class ReserverController {

    @Autowired
    private WxMakeCarService wxMakeCarService;

    @RequestMapping(value={"/add"})
    public Map<String,Object> getAllUsers(@RequestBody Map<String,Object> data){
        String phone = data.get("phone").toString();
        String userName = data.get("userName").toString();
        Map<String,Object> map = new HashMap<String,Object>();

        WxMakeCar wxMakeCar = new WxMakeCar();
        wxMakeCar.setPhone(phone);
        wxMakeCar.setUserName(userName);
        List<WxMakeCar> list = wxMakeCarService.selectMakeList(new WxMakeCar(data.get("phone").toString()));
        if(list.size() > 0){
            map.put("rspCode","999");
            map.put("rspMsg","您的手机号已预约，请勿重复预约。");
            return map;
        }
        if(StringUtils.isEmpty(data.get("phone"))){
            map.put("rspCode","999");
            map.put("rspMsg","请填写正确的手机号！");
            return map;
        }
        int result = wxMakeCarService.insert(wxMakeCar);
        if(result > 0){
            map.put("rspCode","000");
            map.put("rspMsg","预约成功，客服会在24小时内电话联系您，请保持电话畅通 谢谢！");
        }else{
            map.put("rspCode","999");
            map.put("rspMsg","预约失败，请重新进入预约！");
        }
        return map;
    }
}
